package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @AutoFill(OperationType.INSERT)
    void save(@Param("dish") Dish dish);

    @Select("select * from dish where id=#{id}")
    Dish selectById(Long id);

    List<Dish> getCategoryById(Long categoryId);


    Page<Dish> pageQuery(@Param("name") String name, @Param("categoryId") Integer categoryId, @Param("status") Integer status);

    @AutoFill(OperationType.UPDATE)
    void update(@Param("dish") Dish dish);

    @Delete("delete from dish where id in (${id})")
    void deleteById(Long id);

    @Update("update dish set status = #{status} where id = #{id}")
    void changeStatus(Integer status, Long id);

    @Select("select count(id) from dish where status = #{status}")
    Integer getByStatus(Integer enable);
}
